package com.codegen;

public class CodeGeneratorUtils {
    
    // MySQL类型转Java类型
    public static String convertType(String sqlType) {
        if (sqlType == null || sqlType.isEmpty()) return "String";

        String lowerType = sqlType.toLowerCase();
        if (lowerType.contains("varchar") || lowerType.contains("text") ||
            lowerType.startsWith("char")) {
            return "String";
        } else if (lowerType.contains("bigint")) {
            return "Long";
        } else if (lowerType.contains("int") || lowerType.contains("tinyint")) {
            return "Integer";
        } else if (lowerType.contains("datetime") || lowerType.contains("timestamp")) {
            return "Date";
        } else if (lowerType.contains("date")) {
            return "Date";
        } else if (lowerType.contains("decimal") || lowerType.contains("numeric")) {
            return "BigDecimal";
        } else if (lowerType.contains("bit")) {
            return "Boolean";
        } else if (lowerType.contains("double") || lowerType.contains("float")) {
            return "Double";
        }
        return "String";
    }

    // 下划线转驼峰命名
    public static String toCamelCase(String input, boolean capitalizeFirst) {
        if (input == null || input.isEmpty()) return "";
        
        StringBuilder result = new StringBuilder();
        boolean nextUpper = capitalizeFirst;
        
        for (char c : input.toCharArray()) {
            if (c == '_') {
                nextUpper = true;
            } else {
                if (nextUpper) {
                    result.append(Character.toUpperCase(c));
                    nextUpper = false;
                } else {
                    result.append(Character.toLowerCase(c));
                }
            }
        }
        return result.toString();
    }
}